package viewmodel;

import java.util.List;

import org.zkoss.bind.BindUtils;
import org.zkoss.bind.annotation.BindingParam;
import org.zkoss.bind.annotation.Command;
import org.zkoss.bind.annotation.NotifyChange;
import org.zkoss.zk.ui.util.Clients;

import admin.dao.GameDAO;


public class GamesDataVM {
	
	private List<GamesEditStatus> gameEditData;
	private boolean displayEdit = true;
	
	public GamesDataVM(){
		gameEditData = new GameDataModel().convertGameToEditData();
	}

	public List<GamesEditStatus> getGameEditData() {
		return gameEditData;
	}

	public void setGameEditData(List<GamesEditStatus> gameEditData) {
		this.gameEditData = gameEditData;
	}

	public boolean isDisplayEdit() {
		return displayEdit;
	}

	public void setDisplayEdit(boolean displayEdit) {
		this.displayEdit = displayEdit;
	}
	
	@Command
	public void delGame(@BindingParam("gameEditStatus") GamesEditStatus ges){
		GameDAO.removeGame(ges.getGame());
		gameEditData.remove(ges);
		refreshRowTemplate(ges);
	}
	@Command
	public void changeEditableStatus(@BindingParam("gameEditStatus")GamesEditStatus ges){
		ges.setEditingStatus(!ges.isEditingStatus());
		refreshRowTemplate(ges);
	}
	@Command
	public void confirm(@BindingParam("gameEditStatus")GamesEditStatus ges){
		changeEditableStatus(ges);
		GameDAO.updateGame(ges);
		refreshRowTemplate(ges);
	}
	public void refreshRowTemplate(GamesEditStatus gameEditData){
		BindUtils.postNotifyChange(null, null, gameEditData, "editingStatus");
	}
	
}
